package com.yihen.controller;

import com.yihen.dto.LoginFormDTO;
import com.yihen.dto.Result;
import com.yihen.service.OrderService;
import com.yihen.service.UserService;
import com.yihen.util.UserHolder;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/orders")
@Slf4j
public class OrderController {
    @Resource
    private OrderService orderService;


    // 下单
    @GetMapping("/create/{goodsId}")
    public Result buyGoods(@PathVariable Long goodsId) {

        return orderService.createOrder(goodsId);
    }

    // 获取自己购买的订单
    @GetMapping("/buyorders")
    public Result getMyBuyOrders() {
        return orderService.getMyBuyOrder();
    }


    // 获取自己卖出的订单
    @GetMapping("/sellorders")
    public Result getMySellOrders() {
        return orderService.getMySellOrder();
    }

    // 完成订单
    @GetMapping("/complete/{orderId}/{appraise}")
    public Result completeOrder(@PathVariable Long orderId, @PathVariable int appraise) {

        return orderService.completeOrder(orderId, appraise);
    }

    // 取消订单
    @GetMapping("/cancel/{orderId}")
    public Result cancelOrder(@PathVariable Long orderId) {

        return orderService.cancelOrder(orderId);
    }


    // 搜索订单
    @GetMapping("/select/{mode}/{orderId}")
    public Result selectOrder(@PathVariable int mode,@PathVariable String orderId) {
        return orderService.selectOrderByOrderId(mode,orderId);
    }

    // 获取全部订单
    @GetMapping("/all")
    public Result getAllOrders() {
        return orderService.getAllOrders();
    }


    // 重置订单评价
    @GetMapping("/resetappraise/{orderId}")
    public Result resetAppraise(@PathVariable Long orderId) {
        return orderService.resetAppraise(orderId);
    }
}
